#Region "using directives"
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports C4F.DevKit.PictureAcquisition
#End Region
Namespace PictureAcquisitionApplication
	Public Partial Class FrmPictureAcquisition
	Inherits Form
		#Region "Globals"
		Private pictureAcquisitionManager As PictureAcquisitionManager = New PictureAcquisitionManager()
		Private deviceInfo As DeviceInfo = New DeviceInfo()
		Private deviceDetails As DeviceDetails = New DeviceDetails()
#End Region

		#Region "Constructor"
		Public Sub New()
			InitializeComponent()
			FrmPictureAcquisitionInitialize()
		End Sub
#End Region

		#Region "Form Initialization"
		Private Sub FrmPictureAcquisitionInitialize()
			rdbtnAcquisition.Checked = True
			chkbxAllDevice.Checked = True
			chkbxSupressProgressDialog.Checked = False
			RdbtnDeviceSelectionDialogChecked()
			rdbtnDeviceInfo.Checked = False
			rdbtnSettingsDialog.Checked = False
			rdbtnDeviceItems.Checked = False
		End Sub
#End Region

		#Region "Radio Button Checked And Unchecked Method"
		Private Sub RdbtnDeviceSelectionDialogChecked()
			chkbxAllDevice.Enabled = True
			If chkbxAllDevice.Checked Then
				pnlDeviceSelectionOptions.Enabled = False
				chkbxWIAcameras.Checked = True
				chkbxWIAscanners.Checked = True
				chkbxSTIdevices.Checked = True
				chkbxFSdevices.Checked = True
				chkbxCardRecorderDevice.Checked = True
				chkbxWPDdevices.Checked = True
				chkbxDigitalVideoCameras.Checked = True
				chkbxOfflineDevices.Checked = True
			Else
				pnlDeviceSelectionOptions.Enabled = True
				chkbxWIAcameras.Checked = False
				chkbxWIAscanners.Checked = False
				chkbxSTIdevices.Checked = False
				chkbxFSdevices.Checked = False
				chkbxCardRecorderDevice.Checked = False
				chkbxWPDdevices.Checked = False
				chkbxDigitalVideoCameras.Checked = False
				chkbxOfflineDevices.Checked = False
			End If
			pnlAcquisitionControl.Enabled = True
			If chkbxTargetLocation.Checked Then
				chkbxTargetLocation.Checked = True
				tbxTargetLocation.Enabled = True
			Else
				chkbxTargetLocation.Checked = False
				tbxTargetLocation.Enabled = False
			End If
			If chkbxSupressProgressDialog.Checked Then
				chkbxSupressProgressDialog.Checked = True
			Else
				chkbxSupressProgressDialog.Checked = False
			End If
		End Sub
		Private Sub RdbtnDeviceSelectionDialogUnchecked()
			pnlDeviceSelectionOptions.Enabled = False
			chkbxAllDevice.Enabled = False
			If chkbxAllDevice.Checked Then
				chkbxAllDevice.Checked = True
			Else
				chkbxAllDevice.Checked = False
			End If
			If chkbxWIAcameras.Checked Then
				chkbxWIAcameras.Checked = True
			Else
				chkbxWIAcameras.Checked = False
			End If
			If chkbxWIAscanners.Checked Then
				chkbxWIAscanners.Checked = True
			Else
				chkbxWIAscanners.Checked = False
			End If
			If chkbxSTIdevices.Checked Then
				chkbxSTIdevices.Checked = True
			Else
				chkbxSTIdevices.Checked = False
			End If
			If chkbxFSdevices.Checked Then
				chkbxFSdevices.Checked = True
			Else
				chkbxFSdevices.Checked = False
			End If
			If chkbxCardRecorderDevice.Checked Then
				chkbxCardRecorderDevice.Checked = True
			Else
				chkbxCardRecorderDevice.Checked = False
			End If
			If chkbxWPDdevices.Checked Then
				chkbxWPDdevices.Checked = True
			Else
				chkbxWPDdevices.Checked = False
			End If
			If chkbxDigitalVideoCameras.Checked Then
				chkbxDigitalVideoCameras.Checked = True
			Else
				chkbxDigitalVideoCameras.Checked = False
			End If
			If chkbxOfflineDevices.Checked Then
				chkbxOfflineDevices.Checked = True
			Else
				chkbxOfflineDevices.Checked = False
			End If
			pnlAcquisitionControl.Enabled = False
			If chkbxTargetLocation.Checked Then
				chkbxTargetLocation.Checked = True
			Else
				chkbxTargetLocation.Checked = False
			End If
			If chkbxSupressProgressDialog.Checked Then
				chkbxSupressProgressDialog.Checked = True
			Else
				chkbxSupressProgressDialog.Checked = False
			End If
		End Sub
#End Region

		#Region "Helper Methods"
		Private Sub DeviceSelectionDialogOperation()
			Dim listOfDeviceFlags As List(Of DeviceFlag) = New List(Of DeviceFlag)()
			Dim hImport As Boolean = False
			Dim showProcessDialog As Boolean = False
			Dim flag As DeviceFlag = DeviceFlag.None
			Try
				If Not chkbxSupressProgressDialog.Checked Then
					showProcessDialog = True
				End If
				If chkbxAllDevice.Checked Then
					hImport = pictureAcquisitionManager.ShowAllDeviceDialog(Me.Handle, "Devices Connected", "Import")
				Else
					If chkbxCardRecorderDevice.Checked Or chkbxDigitalVideoCameras.Checked Or chkbxFSdevices.Checked Or chkbxOfflineDevices.Checked Or chkbxSTIdevices.Checked Or chkbxWIAcameras.Checked Or chkbxWIAscanners.Checked Or chkbxWPDdevices.Checked Then
						If chkbxCardRecorderDevice.Checked Then
							flag = DeviceFlag.CardReaders
						End If
						If chkbxDigitalVideoCameras.Checked Then
							flag = flag Or DeviceFlag.DigitalVideoCameras
						End If
						If chkbxFSdevices.Checked Then
							flag = flag Or DeviceFlag.FS
						End If
						If chkbxOfflineDevices.Checked Then
							flag = flag Or DeviceFlag.OffLine
						End If
						If chkbxSTIdevices.Checked Then
							flag = flag Or DeviceFlag.Sti
						End If
						If chkbxWIAcameras.Checked Then
							flag = flag Or DeviceFlag.Cameras
						End If
						If chkbxWIAscanners.Checked Then
							flag = flag Or DeviceFlag.Scanners
						End If
						If chkbxWPDdevices.Checked Then
							flag = flag Or DeviceFlag.Wpd
						End If
					End If
					If flag = DeviceFlag.None Then
						MessageBox.Show("Please select atleast one device!", "Picture Acquisition", MessageBoxButtons.OK, MessageBoxIcon.Information)
					Else
						hImport = pictureAcquisitionManager.ShowDeviceSelectionDialog(Me.Handle, flag, "Devices Connected", "Import")
					End If
				End If
				If hImport = True Then
					If Not tbxTargetLocation.Enabled Then
						deviceInfo = pictureAcquisitionManager.GetSelectedDevice()
						pictureAcquisitionManager.AcquireItems(deviceInfo.Id, showProcessDialog)
					Else
						deviceInfo = pictureAcquisitionManager.GetSelectedDevice()
						pictureAcquisitionManager.AcquireItems(deviceInfo.Id, showProcessDialog, tbxTargetLocation.Text)
					End If
				End If
			Catch ex As ArgumentNullException
				MessageBox.Show(ex.Message, "Picture Acquisition", MessageBoxButtons.OK, MessageBoxIcon.[Error])
			Catch ex As ArgumentException
				MessageBox.Show(ex.Message, "Picture Acquisition", MessageBoxButtons.OK, MessageBoxIcon.[Error])
			Catch ex As PictureAcquisitionException
				MessageBox.Show(ex.Message, "Picture Acquisition", MessageBoxButtons.OK, MessageBoxIcon.[Error])
			End Try
		End Sub
		Private Sub DeviceInfoOperation()
			Dim hImport As Boolean = True
			Try
				hImport = pictureAcquisitionManager.ShowAllDeviceDialog(Me.Handle, "Devices Connected", "Get Device Info")
				If hImport = True Then
					deviceInfo = pictureAcquisitionManager.GetSelectedDevice()
					Dim deviceDetails As New DeviceDetails(deviceInfo)
					deviceDetails.ShowDialog()
				End If
			Catch ex As ArgumentNullException
				MessageBox.Show(ex.Message, "Picture Acquisition", MessageBoxButtons.OK, MessageBoxIcon.[Error])
			Catch ex As ArgumentException
				MessageBox.Show(ex.Message, "Picture Acquisition", MessageBoxButtons.OK, MessageBoxIcon.[Error])
			Catch ex As PictureAcquisitionException
				MessageBox.Show(ex.Message, "Picture Acquisition", MessageBoxButtons.OK, MessageBoxIcon.[Error])
			End Try
		End Sub
		Private Sub DeviceItemsOperation()
			Dim hImport As Boolean = True
			Try
				hImport = pictureAcquisitionManager.ShowAllDeviceDialog(Me.Handle, "Devices Connected", "Get Items")
				If hImport = True Then
					deviceInfo = pictureAcquisitionManager.GetSelectedDevice()
					Dim deviceItemsDetails As New DeviceItemsDetails(pictureAcquisitionManager, deviceInfo.Id.ToString())
					deviceItemsDetails.ShowDialog()
				End If
			Catch ex As ArgumentNullException
				MessageBox.Show(ex.Message, "Picture Acquisition", MessageBoxButtons.OK, MessageBoxIcon.[Error])
			Catch ex As ArgumentException
				MessageBox.Show(ex.Message, "Picture Acquisition", MessageBoxButtons.OK, MessageBoxIcon.[Error])
			Catch ex As PictureAcquisitionException
				MessageBox.Show(ex.Message, "Picture Acquisition", MessageBoxButtons.OK, MessageBoxIcon.[Error])
			End Try
		End Sub
		Private Sub DeviceItemsInThumbnailsOperation()
			Dim hImport As Boolean = True
			Try
				hImport = pictureAcquisitionManager.ShowAllDeviceDialog(Me.Handle, "Devices Connected", "Get Items")
				If hImport = True Then
					deviceInfo = pictureAcquisitionManager.GetSelectedDevice()
					Dim deviceItemsDetailsInThumbnails As New DeviceItemsDetailsInThumbnails(pictureAcquisitionManager, deviceInfo.Id.ToString())
					deviceItemsDetailsInThumbnails.ShowDialog()
				End If
			Catch ex As ArgumentNullException
				MessageBox.Show(ex.Message, "Picture Acquisition", MessageBoxButtons.OK, MessageBoxIcon.[Error])
			Catch ex As ArgumentException
				MessageBox.Show(ex.Message, "Picture Acquisition", MessageBoxButtons.OK, MessageBoxIcon.[Error])
			Catch ex As PictureAcquisitionException
				MessageBox.Show(ex.Message, "Picture Acquisition", MessageBoxButtons.OK, MessageBoxIcon.[Error])
			End Try
		End Sub
#End Region

		#Region "EventHandler"
        Private Sub rdbtnDeviceSelectionDialog_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles rdbtnAcquisition.CheckedChanged
            If rdbtnAcquisition.Checked = True Then
                chkbxAllDevice.Checked = True
                RdbtnDeviceSelectionDialogChecked()
            Else
                RdbtnDeviceSelectionDialogUnchecked()
            End If
        End Sub
        Private Sub chkbxAllDevice_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles chkbxAllDevice.CheckedChanged
            RdbtnDeviceSelectionDialogChecked()
        End Sub
        Private Sub rdbtnDeviceInfo_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles rdbtnDeviceInfo.CheckedChanged
            If rdbtnDeviceInfo.Checked = True Then
                RdbtnDeviceSelectionDialogUnchecked()
            End If
        End Sub
        Private Sub rdbtnSettingsDialog_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles rdbtnSettingsDialog.CheckedChanged
            If rdbtnSettingsDialog.Checked = True Then
                RdbtnDeviceSelectionDialogUnchecked()
            End If
        End Sub
		Private Sub rdbtnDeviceItemDetailsInThumbnail_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
			If rdbtnDeviceItemDetailsInThumbnail.Checked Then
				RdbtnDeviceSelectionDialogUnchecked()
			End If
		End Sub
        Private Sub rdbtnDeviceItems_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles rdbtnDeviceItems.CheckedChanged
            If rdbtnDeviceItems.Checked Then
                RdbtnDeviceSelectionDialogUnchecked()
            End If
        End Sub
        Private Sub chkbxCustomFilenameTemplate_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles chkbxTargetLocation.CheckedChanged
            If chkbxTargetLocation.Checked Then
                tbxTargetLocation.Enabled = True
            Else
                tbxTargetLocation.Enabled = False
            End If
        End Sub
        Private Sub btnOK_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnOK.Click
            Try
                If rdbtnAcquisition.Checked Then
                    DeviceSelectionDialogOperation()
                ElseIf rdbtnDeviceInfo.Checked Then
                    DeviceInfoOperation()
                ElseIf rdbtnSettingsDialog.Checked Then
                    pictureAcquisitionManager.ShowImportSettings()
                ElseIf rdbtnDeviceItems.Checked Then
                    DeviceItemsOperation()
                ElseIf rdbtnDeviceItemDetailsInThumbnail.Checked Then
                    DeviceItemsInThumbnailsOperation()
                End If
            Catch ex As ArgumentNullException
                MessageBox.Show(ex.Message, "Picture Acquisition", MessageBoxButtons.OK, MessageBoxIcon.[Error])
            Catch ex As ArgumentException
                MessageBox.Show(ex.Message, "Picture Acquisition", MessageBoxButtons.OK, MessageBoxIcon.[Error])
            Catch ex As PictureAcquisitionException
                MessageBox.Show(ex.Message, "Picture Acquisition", MessageBoxButtons.OK, MessageBoxIcon.[Error])
            End Try
        End Sub
        Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnCancel.Click
            Application.[Exit]()
        End Sub
		#End Region

    End Class
End Namespace
